package com.huayousoft.demo.order.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

/**
 * @author Chet_Li
 * @description RestTemplate配置
 * @className RestTemplateConfig
 * @date 2020/11/25 9:57
 */
@Configuration
public class RestTemplateConfig {
    /**
     * @Description: @LoadBalanced: 开启消息者端的负载均衡功能，默认是轮询策略
     * @Author: Chet_Li
     * @Date: 2020/11/25 9:59
     * @return: org.springframework.web.client.RestTemplate
     **/
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        //解决编码问题
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return restTemplate;
    }
}
